<div class="modal fade" id="profile-modal" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title"><i class="fa fa-edit"></i> View Profile</h4>
			</div>
			<form action="<?php echo base_url(); ?>control-authors/view-profile" method="post" onsubmit="return validatePassword()" name="form_change_password">
				<div class="modal-body">
					<div class="form-group">
						<label for="username">Username <span class="required">*</span></label>
						<input type="username" class="form-control" id="username" name="username" placeholder="Username" required="required">
						<p class="help-block" id="error_username"></p>
						
					</div>
					<div class="form-group">
						<label for="email">Email <span class="required">*</span></label>
						<input type="email" class="form-control" id="email" name="email" placeholder="Email" required="required">
						<p class="help-block" id="error_email"></p>
					</div>
					<div class="form-group">
						<label for="phone">Phone <span class="required">*</span></label>
						<input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" required="required">
						<p class="help-block" id="error_phone"></p>
					</div>
					<div class="form-group">
						<label for="position">Position <span class="required">*</span></label>
						<input type="text" class="form-control" id="position" name="position" placeholder="Position" required="required">
						<p class="help-block" id="error_position"></p>
					</div>
					<div class="form-group">
						<label for="address">Address</label>
						<textarea class="form-control" rows="7" name="address" id="address"></textarea>
					</div>
				</div>
				<div class="modal-footer clearfix">

					<button type="button" class="btn btn-danger" data-dismiss="modal">
						<i class="fa fa-times"></i> Discard
					</button>

					<button type="button" class="btn btn-primary pull-left" data-dismiss="modal" id="btn_update_profile">
						<i class="fa fa-edit"></i> Update Profile
					</button>
				</div>
			</form>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

	<script id="source" language="javascript" type="text/javascript">
		$( "#view_profile_update" ).click(function() {
		  $.ajax({                                      
		      url: '<?php echo base_url()?>control-authors/view-profile',                  //the script to call to get data          
		      data: "",                        //you can insert url argumnets here to pass to api.php
		                                       //for example "id=5&parent=6"
		      dataType: 'json',                //data format      
		      success: function(data)          //on recieve of reply
		      {
		      	$('#username').val(data[0]);
		      	$('#email').val(data[1]);
		      	$('#phone').val(data[2]);
		      	$('#position').val(data[3]);
		      	$('#address').val(data[4]);
		      	
		        //--------------------------------------------------------------------
		        // 3) Update html content
		        //--------------------------------------------------------------------
		        //$('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname); //Set output element html
		        //recommend reading up on jquery selectors they are awesome 
		        // http://api.jquery.com/category/selectors/
		      } 
		    });
		});

	$('#btn_update_profile').click(function(){
		
		
		
		
		var username=$('#username').val();
		var email=$('#email').val();
		var phone=$('#phone').val();
		var position=$('#position').val();
		var address=$('#address').val();
		
		/*$('#error_username').html("");
		$('#error_email').html("");
		$('#error_phone').html("");
		$('#error_position').html("");
		
		valid=required(username,"username","Username");
		valid=required(email,"email","Email");
		valid=required(phone,"phone","Phone");
		valid=required(position,"position","Position");
		//valid=required(username,"username","Username");
		
		
		return false;*/
		
		$.post("<?php echo base_url()?>control-authors/update-profile",{"username":username,"email":email,"phone":phone,"position":position,"address":address},function(result){
	    	alert(result);  
	    });
	    return true;
		
		
	});
 	
 	function required(data,field,label){
 		if (data == null || data == "") {
			$('#error_'+field).html(label+" field must be filled out");
			return false;
		} else {
			$('#error'+field).html("");
		}
 	}
	
  </script>
